package se.gala.rng;

import java.io.Serializable;

import se.gala.utils.GGObject;

final class RNGServerFacade extends GGObject implements Runnable, Serializable {
	
	private static final long serialVersionUID = 6321522188657949722L;
	final private GGRandom r;
	final private boolean replayMode;
	
	protected RNGServerFacade() {
		r = new GGRandom();
		replayMode = false;
	}

	protected RNGServerFacade(long seed) {
		r = new GGRandom(seed);
		replayMode = true;
	}

	@Override
	public void run() {
		if (replayMode) {
			log("************************************************************************", LogLevel.Warning);
			log("**************************** W A R N I N G *****************************", LogLevel.Warning);
			log("**** RNG started in REPLAY mode, seed is: " + r.getSeed() +	  "L ****", LogLevel.Warning);
			log("************************************************************************", LogLevel.Warning);
			log("************************************************************************", LogLevel.Warning);
		} else {
			log("RNG initiated in PROD mode, seed is: " + r.getSeed() + "L ", LogLevel.Notice);
		}		
	}
	
	protected synchronized boolean getBool() {
		return r.nextBoolean();
	}
	
	protected synchronized int getInt(int bound) {
		return r.nextInt(bound);
	}
	
	protected synchronized long getLong() {
		return r.nextLong();
	}
}
